In this script we conduct the comparison procedure of the obtained estimates.
current_gas_cost = read.csv("program_generator/data/current_gas_cost.csv")
if (exists("estimated_cost")) {
rm(estimated_cost)
}
for (env in all_envs) {
if (exists("estimated_cost")) {
estimated_cost = rbind(estimated_cost, read.csv(paste0("../../local/", env, "_argument_estimated_cost.csv")))
} else {
estimated_cost = read.csv(paste0("../../local/", env, "_argument_estimated_cost.csv"))
}
}
if (exists("marginal")) {
rm(marginal)
}
for (env in all_envs) {
if (exists("marginal")) {
marginal = rbind(marginal, read.csv(paste0("../../local/", env, "_marginal_estimated_cost.csv")))
} else {
marginal = read.csv(paste0("../../local/", env, "_marginal_estimated_cost.csv"))
}
}
order1 = order(estimated_cost$opcode, estimated_cost$env)
order2 = order(marginal$op, marginal$env)
estimated_cost[order1, 'estimate_marginal_ns'] = marginal[order2, 'estimate_marginal_ns']
estimated_cost[order1, 'estimate_marginal_ns_stderr'] = marginal[order2, 'estimate_marginal_ns_stderr']
estimated_cost$arg0_ns[which(is.na(estimated_cost$arg0_ns))] = 0
estimated_cost$arg1_ns[which(is.na(estimated_cost$arg1_ns))] = 0
estimated_cost$arg2_ns[which(is.na(estimated_cost$arg2_ns))] = 0
estimated_cost$expensive_ns[which(is.na(estimated_cost$expensive_ns))] = 0
head(estimated_cost)
## opcode env has_significant has_impacting estimate_marginal_ns arg0_ns
## 1 ADD geth FALSE FALSE 18.92828 0
## 2 MUL geth FALSE FALSE 26.40941 0
## 3 SUB geth FALSE FALSE 19.11652 0
## 4 DIV geth TRUE TRUE 20.29842 0
## 5 SDIV geth TRUE TRUE 25.49620 0
## 6 MOD geth TRUE TRUE 25.14855 0
## arg1_ns arg2_ns expensive_ns arg0_ns_stderr arg1_ns_stderr arg2_ns_stderr
## 1 0 0 0.00000 NA NA NA
## 2 0 0 0.00000 NA NA NA
## 3 0 0 0.00000 NA NA NA
## 4 0 0 86.48910 NA NA NA
## 5 0 0 92.19008 NA NA NA
## 6 0 0 84.52555 NA NA NA
## expensive_ns_stderr estimate_marginal_ns_stderr
## 1 NA 0.3330197
## 2 NA 0.4378314
## 3 NA 0.2954671
## 4 0.4183415 0.4458911
## 5 0.4125533 0.6418997
## 6 0.4293301 0.4993063
head(marginal)
## op estimate_marginal_ns estimate_marginal_ns_stderr env
## 1 ADD 18.92828 0.3330197 geth
## 2 MUL 26.40941 0.4378314 geth
## 3 SUB 19.11652 0.2954671 geth
## 4 DIV 20.29842 0.4458911 geth
## 5 SDIV 25.49620 0.6418997 geth
## 6 MOD 25.14855 0.4993063 geth
Here we calculate the scales. Each estimated evm gas cost is scaled to get the best match with the current gas schedule. There are many PUSH, DUP and SWAP opcodes. To avoid other opcodes being overran, we use only PUSH1, DUP1 and SWAP1 as representatives when calculating the scales.
# [SECTION] original
extract_opcodes <- function() {
unique(estimated_cost$opcode)
}
all_opcodes = extract_opcodes()
excluded_opcodes = c('PUSH2', 'PUSH3', 'PUSH4', 'PUSH5', 'PUSH6', 'PUSH7', 'PUSH8', 'PUSH9', 'PUSH10', 'PUSH11', 'PUSH12', 'PUSH13', 'PUSH14', 'PUSH15', 'PUSH16',
'PUSH17', 'PUSH18', 'PUSH19', 'PUSH20', 'PUSH21', 'PUSH22', 'PUSH23', 'PUSH24', 'PUSH25', 'PUSH26', 'PUSH27', 'PUSH28', 'PUSH29', 'PUSH30',
'PUSH31', 'PUSH32',
'DUP2', 'DUP3', 'DUP4', 'DUP5', 'DUP6', 'DUP7', 'DUP8', 'DUP9', 'DUP10', 'DUP11', 'DUP12', 'DUP13', 'DUP14', 'DUP15', 'DUP16',
'SWAP2', 'SWAP3', 'SWAP4', 'SWAP5', 'SWAP6', 'SWAP7', 'SWAP8', 'SWAP9', 'SWAP10', 'SWAP11', 'SWAP12', 'SWAP13', 'SWAP14', 'SWAP15', 'SWAP16')
excluded_opcodes_df <- data.frame(excluded_opcodes)
colnames(excluded_opcodes_df) <- 'opcode'
q = c("SELECT ")
for (env in all_envs) {
q <- append(q, paste0("avg(", env, ".estimate_marginal_ns/current_gas_cost.constant_current_gas) as ", env, "_scale,"))
}
q <- append(q, " 1 FROM current_gas_cost")
for (env in all_envs) {
q <- append(q, paste0(" INNER JOIN estimated_cost as ", env, " ON ", env, ".opcode = current_gas_cost.opcode AND ", env, ".env = '", env, "'"))
}
q <- append(q, paste0(" WHERE current_gas_cost.opcode NOT IN (SELECT opcode FROM excluded_opcodes_df)"))
scales <- sqldf(paste(q, collapse = ""))[1:length(all_envs)]
This allows us to have gas cost schedules with the least divergence between EVMs.
q = c("SELECT ")
for (env in all_envs) {
q <- append(q, paste0(env, ".estimate_marginal_ns/", env, "_scale as ", env, "_gas,"))
}
for (env in all_envs) {
q <- append(q, paste0(env, ".estimate_marginal_ns_stderr/", env, "_scale as ", env, "_gas_stderr,"))
}
q <- append(q, " current_gas_cost.opcode, current_gas_cost.constant_current_gas FROM current_gas_cost, scales")
for (env in all_envs) {
q <- append(q, paste0(" INNER JOIN estimated_cost as ", env, " ON ", env, ".opcode = current_gas_cost.opcode AND ", env, ".env = '", env, "'"))
}
gas_schedule_comparison <- sqldf(paste(q, collapse = ""))
We continue to fill in the additional special entries of our gas cost schedule, being the costs of the arguments.
arg_cost <- function(opcode, arg, opcode_name, opcode_current_gas_cost) {
r1 <- list()
r2 <- list()
for (env in all_envs) {
r1 <- append(r1, estimated_cost[which(estimated_cost$env==env & estimated_cost$opcode==opcode),paste0('arg', arg, '_ns')])
r2 <- append(r2, estimated_cost[which(estimated_cost$env==env & estimated_cost$opcode==opcode),paste0('arg', arg, '_ns_stderr')])
}
append(append(r1/scales, r2/scales), list(opcode_name, opcode_current_gas_cost))
}
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = arg_cost('EXP', '1', "EXP_arg1_cost", 50)
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = arg_cost('CALLDATACOPY', '2', "CALLDATACOPY_arg2_cost", 3)
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = arg_cost('RETURNDATACOPY', '2', "RETURNDATACOPY_arg2_cost", 3)
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = arg_cost('CODECOPY', '2', "CODECOPY_arg2_cost", 3)
expensive_cost <- function(opcode, opcode_name, opcode_current_gas_cost) {
r1 <- list()
r2 <- list()
for (env in all_envs) {
v1 <- estimated_cost$expensive_ns[which(estimated_cost$env==env & estimated_cost$opcode==opcode)] + estimated_cost$estimate_marginal_ns[which(estimated_cost$env==env & estimated_cost$opcode==opcode)]
r1 <- append(r1, v1)
v2 <- sqrt(estimated_cost$expensive_ns_stderr[which(estimated_cost$env==env & estimated_cost$opcode==opcode)]^2 + estimated_cost$estimate_marginal_ns_stderr[which(estimated_cost$env==env & estimated_cost$opcode==opcode)]^2)
r2 <- append(r2, v2)
}
append(append(r1/scales, r2/scales), list(opcode_name, opcode_current_gas_cost))
}
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = expensive_cost('DIV', "DIV_expensive_cost", 5)
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = expensive_cost('SDIV', "SDIV_expensive_cost", 5)
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = expensive_cost('MOD', "MOD_expensive_cost", 5)
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = expensive_cost('SMOD', "SMOD_expensive_cost", 5)
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = expensive_cost('ADDMOD', "ADDMOD_expensive_cost", 8)
gas_schedule_comparison[nrow(gas_schedule_comparison) + 1, ] = expensive_cost('MULMOD', "MULMOD_expensive_cost", 8)
gas_schedule_comparison[, c(which(names(gas_schedule_comparison) == 'opcode'), 1:length(all_envs))]
## opcode geth_gas evmone_gas besu_gas
## 1 ADD 2.042429893 0.797790701 2.46738324
## 2 MUL 2.849670995 3.238738591 7.86450987
## 3 SUB 2.062741162 0.782679717 5.76122102
## 4 DIV 2.190272493 5.658245337 2.40253730
## 5 SDIV 2.751132047 7.638832107 5.15458770
## 6 MOD 2.713619672 6.417067883 4.50874204
## 7 SMOD 2.938757391 7.858040966 4.49224928
## 8 ADDMOD 4.655142597 6.797327796 5.48456820
## 9 MULMOD 6.996113961 12.462838529 5.75130064
## 10 EXP 6.690697906 15.399660517 18.33860443
## 11 SIGNEXTEND 3.768394596 1.014661471 7.38657788
## 12 LT 2.066925478 0.728695833 8.10345388
## 13 GT 2.159576112 0.749296997 8.11261926
## 14 SLT 2.516790784 0.832671529 1.76792952
## 15 SGT 2.464899399 0.789096473 1.76162173
## 16 EQ 2.006426216 0.667896852 5.59489779
## 17 ISZERO 1.642488318 0.526918728 3.07955404
## 18 AND 2.041975819 0.504750178 5.72280837
## 19 OR 2.012192468 0.610630984 5.71042392
## 20 XOR 2.049358184 0.482070712 5.70976471
## 21 NOT 1.664440112 0.577750521 3.25828562
## 22 BYTE 2.342099226 0.923753096 6.28426182
## 23 SHL 2.938215432 1.602058775 4.10633994
## 24 SHR 3.024533441 1.530218817 4.33876379
## 25 SAR 3.033195025 2.825286470 4.20626490
## 26 ADDRESS 5.085189768 5.059365416 0.70315916
## 27 ORIGIN 2.291189227 7.122391483 0.61446784
## 28 CALLER 2.931838865 5.102074514 0.66418548
## 29 CALLVALUE 1.969758517 3.112559706 0.68773819
## 30 CALLDATALOAD 1.733425188 3.782734031 4.26413576
## 31 CALLDATASIZE 1.601826721 0.951108741 0.75548125
## 32 CALLDATACOPY 5.478203052 5.690450352 3.01182468
## 33 CODESIZE 1.560173972 0.973311929 0.77044073
## 34 CODECOPY 5.259227069 5.639635878 3.07925009
## 35 GASPRICE 2.021864733 5.045813158 0.64236595
## 36 RETURNDATASIZE 1.652409592 0.995653671 0.72076949
## 37 RETURNDATACOPY 6.857318665 4.983005152 3.58065639
## 38 COINBASE 2.322998822 7.495922894 0.70376547
## 39 TIMESTAMP 1.981842746 2.575994195 0.74224072
## 40 NUMBER 2.027030436 2.483527094 0.73361821
## 41 DIFFICULTY 2.033782956 5.056620326 0.67111717
## 42 GASLIMIT 1.651970165 2.522512568 0.75279684
## 43 CHAINID 2.028421953 5.265524274 0.65101662
## 44 SELFBALANCE 9.160743478 4.725330394 28.00137084
## 45 POP 1.376933128 0.631994192 1.56501095
## 46 MLOAD 4.286087821 2.667846465 1.57281181
## 47 MSTORE 13.567595462 1.766192643 2.96755771
## 48 MSTORE8 3.051528875 0.743893413 1.83550562
## 49 JUMP 2.435701950 0.458287768 1.03009392
## 50 JUMPI 3.106960085 0.824929856 1.13779641
## 51 PC 1.605605789 0.949056418 0.72216977
## 52 MSIZE 1.610639663 0.926316335 0.68358587
## 53 GAS 1.614116015 0.966271683 0.77362674
## 54 JUMPDEST 1.246013430 0.885997284 0.56277809
## 55 PUSH1 1.740016586 0.913205716 0.77595452
## 56 PUSH2 2.475963181 0.934562218 0.72697484
## 57 PUSH3 2.444944554 1.557589839 0.76980008
## 58 PUSH4 2.398160281 1.599263575 0.81965378
## 59 PUSH5 2.453645198 1.317764472 0.75329622
## 60 PUSH6 2.490683969 1.115856103 0.78206927
## 61 PUSH7 2.667616602 1.060430861 0.75871398
## 62 PUSH8 2.610061497 1.172539195 0.76519321
## 63 PUSH9 2.594881753 1.094953768 0.75002349
## 64 PUSH10 2.592362375 1.140549040 0.75811001
## 65 PUSH11 2.617546395 1.222627396 0.78734730
## 66 PUSH12 2.682190914 1.202994924 0.75709095
## 67 PUSH13 2.608611390 1.350068882 0.77909286
## 68 PUSH14 2.656679765 1.397145076 0.77652228
## 69 PUSH15 2.670985538 1.599033060 0.75332080
## 70 PUSH16 2.698835412 1.641475341 0.76596980
## 71 PUSH17 2.608328204 1.710167764 0.80173721
## 72 PUSH18 2.664213488 1.763904576 0.75870630
## 73 PUSH19 2.763992595 1.786577572 0.76073540
## 74 PUSH20 2.670746295 1.731190109 0.78885925
## 75 PUSH21 2.667562894 1.660320519 0.76332325
## 76 PUSH22 2.665897956 1.662633845 0.78544098
## 77 PUSH23 2.764549202 1.665290826 0.74350998
## 78 PUSH24 2.688552833 1.833913393 0.79143315
## 79 PUSH25 2.695481123 1.775793411 0.77100798
## 80 PUSH26 2.654731641 1.965467677 0.71602292
## 81 PUSH27 2.733755170 1.568048090 0.81477869
## 82 PUSH28 2.701794217 1.792864157 0.72389471
## 83 PUSH29 2.752875105 1.527027913 0.80689816
## 84 PUSH30 2.781125346 1.575011139 0.80658894
## 85 PUSH31 2.802745129 1.691689344 0.80141091
## 86 PUSH32 2.939416531 1.452365546 0.72958487
## 87 DUP1 1.854301649 0.593008718 0.74163431
## 88 DUP2 1.801048042 0.547355360 0.74780419
## 89 DUP3 1.788094726 0.495770183 0.75397405
## 90 DUP4 1.789129819 0.549754067 0.75639374
## 91 DUP5 1.819284241 0.576269731 0.71906987
## 92 DUP6 1.821325133 0.584002745 0.74348678
## 93 DUP7 1.847246413 0.556387313 0.75839305
## 94 DUP8 1.710492008 0.527689432 0.76774491
## 95 DUP9 1.811276914 0.539544410 0.74859104
## 96 DUP10 1.773779187 0.552213390 0.73791089
## 97 DUP11 1.778456638 0.591805035 0.77825349
## 98 DUP12 1.809406910 0.600914924 0.76193957
## 99 DUP13 1.790081910 0.515695899 0.85222317
## 100 DUP14 1.834234507 0.597745514 0.75534604
## 101 DUP15 1.819010820 0.624694158 0.77315945
## 102 DUP16 1.834576283 0.635250198 0.75225374
## 103 SWAP1 1.900402370 0.919050939 1.78586800
## 104 SWAP2 1.964421927 0.888179501 1.77024357
## 105 SWAP3 1.972678262 0.894899342 1.79643081
## 106 SWAP4 1.913448454 0.850466987 1.76496208
## 107 SWAP5 1.929482639 0.893505149 1.74863755
## 108 SWAP6 1.900597671 0.884317324 1.76700932
## 109 SWAP7 1.989376469 0.844872891 1.79954007
## 110 SWAP8 1.871082859 0.915829571 1.77931820
## 111 SWAP9 2.020336506 0.790430050 1.73778245
## 112 SWAP10 1.879920214 0.973770888 1.72901756
## 113 SWAP11 1.834005028 0.827198668 1.76631024
## 114 SWAP12 1.846157612 0.904312317 1.72818167
## 115 SWAP13 1.830523794 0.884083515 1.77167555
## 116 SWAP14 1.865541202 0.906373299 1.64249073
## 117 SWAP15 1.931479588 0.902225356 1.73200666
## 118 SWAP16 1.920655049 0.879944231 1.73914010
## 119 EXP_arg1_cost 10.660091899 41.042200496 12.34716377
## 120 CALLDATACOPY_arg2_cost 0.002889574 0.004506260 0.01042465
## 121 RETURNDATACOPY_arg2_cost 0.003045237 0.004146076 0.01034729
## 122 CODECOPY_arg2_cost 0.002767216 0.004215134 0.01041845
## 123 DIV_expensive_cost 11.522759112 10.191971267 6.44016597
## 124 SDIV_expensive_cost 12.698774608 13.591478498 9.81332781
## 125 MOD_expensive_cost 11.834231808 11.334489195 9.65598853
## 126 SMOD_expensive_cost 12.205180305 13.413348369 9.51392479
## 127 ADDMOD_expensive_cost 15.559378535 14.393814170 13.43621973
## 128 MULMOD_expensive_cost 19.279543815 19.422208444 15.33908986
## nethermind_gas ethereumjs_gas erigon_gas revm_gas
## 1 1.7910045023 1.90389070022 2.297045249 1.7816783466977317296198180
## 2 4.8148832255 2.03000096785 2.728173630 2.9948181492758392252540034
## 3 2.0055476465 1.92394817227 2.108940100 1.8516529217668125095741516
## 4 2.5443851044 1.63948838120 2.249890955 6.9629190245126233449468600
## 5 3.3621489735 1.25580115131 2.548737250 12.3539663479333921003444630
## 6 2.3100689590 1.97739232917 2.510656585 7.2127278672439212314770884
## 7 3.6695639684 1.66258248849 2.782043839 8.8330705232915338598331800
## 8 3.9410748804 2.13016701610 2.945476338 13.0708447469541138019621940
## 9 10.8830753962 2.12647515236 6.756698378 15.4770647137469268272980116
## 10 20.8823590183 10.19088289798 9.365724061 16.1688490515464984298432682
## 11 2.8281999635 2.52513721834 3.172912455 6.0367803513589670671990461
## 12 2.6751489796 2.10496385464 2.094174614 1.9026996279521797283962314
## 13 1.7282998548 2.10693553380 2.354761630 1.9578831467183208658866533
## 14 2.3449310201 1.52548413730 2.513085746 3.2774092803830661146946568
## 15 2.3444924039 1.62234815040 2.462871185 3.2601985789857073072539606
## 16 1.6091922895 2.15873238920 2.126241916 1.6615937022540077094845401
## 17 1.1251107475 1.14987542162 1.809629406 1.5784671853007767872156819
## 18 3.5210660167 1.66001887404 1.896352822 1.4444500682972902794176662
## 19 3.2800130621 1.58921391911 2.252629714 1.4411328129259202146528196
## 20 3.4208160404 1.65165841737 2.267931045 1.3974621216251315036771530
## 21 2.5550297320 1.45714857626 1.773394427 1.2417462518394888348893801
## 22 1.9521489363 2.29153759123 2.388114958 4.7736475590075624353403327
## 23 3.5275069706 1.90726945440 2.474731205 5.2240137588387201006412397
## 24 3.0137754032 1.14636432711 2.639342560 6.5882643002163350232081029
## 25 3.7520153169 1.29238414290 2.717742529 8.6644758973582689520753775
## 26 1.6663696453 2.57098595119 5.495606783 1.5618809084439095880014747
## 27 1.6388518532 2.55016800172 3.219399921 1.7175187251619874473362870
## 28 1.5210419658 2.55015937083 2.606572707 1.5836186877598479316731073
## 29 1.0222052494 1.34896730700 1.131167225 1.6778677668406334344552988
## 30 2.2897279558 1.38618275112 1.822906436 2.5702875148076196332169729
## 31 1.2505384385 1.30604780275 1.497744234 1.3694800969042504323880394
## 32 10.5329996207 11.52115617400 6.589812662 4.4431708709512172106315120
## 33 1.2351378924 1.38945529739 1.404733579 1.4415621047975089030757090
## 34 10.6524483050 9.89508810947 4.646472252 5.8361449411915433671538267
## 35 1.1631778066 1.19575723956 1.366319500 1.7285632342219687807016726
## 36 1.8566078466 1.27628057804 1.333990229 1.3868469044367386366900519
## 37 11.1258169182 11.48635546146 6.868832720 0.0000000000000000000000000
## 38 1.8550974980 4.41785882603 3.084521968 1.5801843527871308747734247
## 39 1.2124020034 1.29200582216 1.580228527 1.6938296191570005877480298
## 40 1.2521626465 1.30387018093 1.663689246 1.6980054582715562450090374
## 41 1.3804681743 7.41919276298 1.465212534 1.8132508125264417131461414
## 42 1.3877798128 1.32050070965 1.882349426 1.6869999757453573163701321
## 43 2.0235846433 1.12390650831 1.679907466 1.6712722826316672719570988
## 44 3.6688324866 1.15388279239 7.969075777 1.3985548645709939830084068
## 45 0.5127309690 0.58018145675 1.624263017 1.1524925690826537394428897
## 46 5.7338391856 4.66572771386 3.283367818 5.3298927449861972505118501
## 47 4.9617780963 11.95350868426 15.851821090 2.9735096618314891259160504
## 48 5.2702737702 4.35076875056 4.055495576 2.5046448849882065879057791
## 49 1.8533820819 0.97903172410 5.424029898 1.9976511846410218709024775
## 50 2.7613878127 2.46495233536 7.903857577 2.4064150994617685697107845
## 51 0.8791049682 1.25283524143 1.202779833 1.3758023953767575253692712
## 52 1.3455931520 1.29136138228 1.303959136 1.4439036968243545988599408
## 53 1.2028274796 1.18206073437 1.284204344 1.3783000935387241803198322
## 54 0.8253831120 0.93411009282 0.871139869 0.9461592849832319851444140
## 55 1.2945029336 6.17701763125 2.099413980 1.3232726809077124396907266
## 56 1.9025003540 6.48430181425 3.779738214 1.3425127620616759127614159
## 57 1.6704609987 6.78382251056 3.878928939 1.4188096356032637856969814
## 58 1.7138203891 7.00245928894 4.269154542 1.3849736308152551522709928
## 59 1.7001527436 7.23794932098 5.165729151 1.4206438826909648653895601
## 60 1.6685725530 7.52310389879 5.288044534 1.4133849474077246899383908
## 61 1.7928886548 7.73590451645 6.081427447 1.5149710148393067399297252
## 62 1.3932839979 7.92482130027 6.604590055 1.3346684287717263117656330
## 63 1.5570980957 8.18365813292 6.971786263 1.3949253969293737842605196
## 64 1.3628542831 8.36152617719 7.502033923 1.4130337086037010330130670
## 65 1.5766898296 8.54094946012 7.860287485 1.5200054376970395519919066
## 66 1.5970880640 8.74941377416 8.443452743 1.3104329512938037716196504
## 67 1.3026094995 8.95393880559 8.666625922 1.5174296864675080875883850
## 68 1.3798494777 9.17319173370 9.260091297 1.5418212700805427051164997
## 69 1.4228144360 9.38342010602 9.587932721 1.7077620917167719571949647
## 70 1.3480446802 9.62228529603 9.716547250 1.3866907983016178995683276
## 71 1.3534332750 9.82274877388 10.458727267 1.5271472933789413950478320
## 72 1.4157852135 10.05828627582 11.077710737 1.5245715421494014929493233
## 73 1.3842803041 10.22137248034 11.374044518 1.6852828082589947911174022
## 74 1.1747978827 10.48039128094 11.953268343 1.5363965818850036093579092
## 75 1.0453376399 10.66942889724 12.372941565 1.6534761832275903792321969
## 76 1.1881566727 10.91733374711 12.804462898 1.6711552030303202798222628
## 77 1.3887132131 11.06593563786 13.263979117 1.6898098861775743273483386
## 78 1.0718741754 11.30872740391 13.584009122 1.5570025917212972910164126
## 79 1.1488521822 11.47588067618 13.839606832 1.6168302680073649568726069
## 80 1.1894809342 11.75322357817 14.764354942 1.7433542905249168608605714
## 81 1.2773936358 11.89265107126 14.966177704 1.7728973765970315046303085
## 82 1.3558037837 12.04102088694 15.305319487 1.7008543952375640984087113
## 83 1.0621704695 12.21673983929 16.048666455 1.7851126816704399047353036
## 84 0.9302368127 12.41289985885 16.356514934 1.7915910862780590750986676
## 85 1.2002389850 12.66831981754 16.894383490 1.8929820210407468650259943
## 86 0.9164901840 12.81064057718 17.371606385 1.7222799622832525301419082
## 87 0.8055070955 1.62863072000 2.048270623 1.3719777950662255250335875
## 88 0.6014178983 1.57201998499 2.221205426 1.4182242375965543601523677
## 89 0.6507138228 1.56580286632 1.984838571 1.4226732624475693089749484
## 90 0.5249110308 1.55145808530 2.015619846 1.3669043456747105302895307
## 91 0.4421954550 1.67676568004 1.959487183 1.3192919744620601463225285
## 92 0.6057045465 1.52807124695 2.212679548 1.3950034499969385937134803
## 93 0.8773854528 1.25363551684 1.416284000 1.3488350605341743460030557
## 94 0.8707286543 1.14845180406 1.539944946 1.4062430917258315066220575
## 95 0.6623117896 1.60706787667 2.062190666 1.4060089325231375223523855
## 96 0.6024784974 1.50148954036 1.863916383 1.4160387517048207417502681
## 97 0.5991929359 1.52509574719 1.328905663 1.3789635446129981932728015
## 98 0.7441297401 1.62886663103 1.953342836 1.4074919408068147230750355
## 99 0.6887835856 1.49182965507 1.352982931 1.4609192655528191462366294
## 100 0.9804660430 1.10429112970 1.472881061 1.4209951214949887443594889
## 101 0.6929533757 1.68962067333 2.067989691 1.3945741581253499052905909
## 102 0.8327834613 1.42511957855 1.219724419 1.4228683951164724508231529
## 103 0.7435625385 0.76924568496 1.854985646 2.1772512931005461034317250
## 104 0.9983900692 0.77384451152 1.806092834 2.1056376036126671635884122
## 105 0.9720199977 0.81432339152 1.747661995 2.0774994727566653551775744
## 106 0.9231311422 0.82568284315 1.760534165 2.1651530676284842513723561
## 107 0.6803469702 0.80128091610 1.811725153 2.2081603078549907337446712
## 108 0.8452593043 0.76440063825 2.264894594 2.1181651209563256976764478
## 109 1.0883367756 0.74253139829 2.649035387 2.1560989117913251789104834
## 110 0.9365523899 0.76915218364 1.726192502 2.1659726248378792234916546
## 111 0.8328663598 0.79763364530 1.657020962 2.2152631370031099500295113
## 112 1.0245697374 0.78178373274 3.197346953 2.2551092279933673268033090
## 113 0.9147784726 0.74676485045 1.809772298 2.0620839919132247786137668
## 114 0.9819502905 0.73093411765 2.390234519 2.0404632921986252114265881
## 115 0.8508602752 0.76211752777 2.355380827 2.1911447391265346240629697
## 116 0.7791121543 0.77264553688 1.710438681 2.1545378504400831687348727
## 117 0.8776567832 0.78633892535 3.504004667 2.1589478487573243725705652
## 118 0.9635317131 0.75935444383 3.078044207 2.1037643299911832350801433
## 119 28.0024002969 8.25124946219 22.273238662 30.3157439080775255035860027
## 120 0.0003359841 0.11272253142 0.001720803 0.0028002643866333345144815
## 121 0.0006515343 0.00010203128 0.001682281 0.0000000000000000002965299
## 122 0.0003019934 0.00005962129 0.020572484 0.0026805296316781109314253
## 123 6.1603951662 1.94889913545 6.789220561 13.3808508939052774877609409
## 124 7.7681610025 1.77972507620 7.392945548 19.2133561517982798250159249
## 125 6.0167756581 2.49668370424 6.533206151 12.9245989054675209928291224
## 126 7.6789301781 1.96779782846 6.492879363 13.6458407494347095934017489
## 127 7.8808877677 2.47553953589 8.919082669 31.9713733154831807325990667
## 128 16.1293989643 2.68563820379 12.550741153 29.6552062918829228976846935
Plot the scaled gas cost schedules.
maximum_gas_cost = max(gas_schedule_comparison[,!names(gas_schedule_comparison) %in% c('opcode')])
curr_env_colors = env_colors[1:length(all_envs)]
plot(gas_schedule_comparison$constant_current_gas, col='grey', xaxt='n', ylim=c(0,maximum_gas_cost * 1.1), xlab="", ylab="")
axis(1, at=1:nrow(gas_schedule_comparison), labels=gas_schedule_comparison$opcode, las=2)
for (i in 1:length(all_envs)) {
points(gas_schedule_comparison[,i], col=curr_env_colors[i], bg=curr_env_colors[i], xaxt='n', pch=21)
}
legend(0, maximum_gas_cost, c(all_envs, "Current gas cost schedule"), fill=c(curr_env_colors, 'grey'), cex=2)
And individual plots of scaled gas schedules for EVMs.
maximum_gas_cost = max(gas_schedule_comparison[,!names(gas_schedule_comparison) %in% c('opcode')])
for (i in 1:length(all_envs)) {
plot(gas_schedule_comparison$constant_current_gas, col='grey', xaxt='n', ylim=c(0,maximum_gas_cost * 1.1), xlab="", ylab="")
axis(1, at=1:nrow(gas_schedule_comparison), labels=gas_schedule_comparison$opcode, las=2)
points(gas_schedule_comparison[,i], col=curr_env_colors[i], bg=curr_env_colors[i], xaxt='n', pch=21)
legend(0, maximum_gas_cost, c(all_envs[i], "Current gas cost schedule"), fill=c(env_colors[i], 'grey'), cex=2)
}
Calculate and plot the alternative gas cost schedule. The calculated values are: - alternative_gas: the average of evms gas schedules, without any weights, - alternative_gas_stderr: the standard deviation of evms gas schedules, - alternative_gas_rel_diff: the relative difference between the current gas schedule and the alternative gas schedule, as a fraction, - alternative_gas_rel_stderr: the relative standard deviation of evms gas schedules, relative to the alternative gas schedule, as a fraction.
gas_schedule_comparison$alternative_gas <- rowMeans(gas_schedule_comparison[, 1:length(all_envs)], na.rm = TRUE)
mf <- function(x){sd(gas_schedule_comparison[x,1:length(all_envs)])/sqrt(length(all_envs))}
gas_schedule_comparison$alternative_gas_stderr <- sapply(1:nrow(gas_schedule_comparison),mf)
gas_schedule_comparison$alternative_gas_rel_stderr <- gas_schedule_comparison$alternative_gas_stderr / gas_schedule_comparison$alternative_gas
gas_schedule_comparison$alternative_gas_rel_diff <- abs((gas_schedule_comparison$constant_current_gas - gas_schedule_comparison$alternative_gas) / gas_schedule_comparison$constant_current_gas)
gas_schedule_comparison[, c('opcode', 'constant_current_gas', 'alternative_gas', 'alternative_gas_rel_diff', 'alternative_gas_rel_stderr')]
## opcode constant_current_gas alternative_gas
## 1 ADD 3 1.868746090
## 2 MUL 5 3.788685062
## 3 SUB 3 2.356675819
## 4 DIV 5 3.378248371
## 5 SDIV 5 5.009315083
## 6 MOD 5 3.950039334
## 7 SMOD 5 4.605186923
## 8 ADDMOD 8 5.574943083
## 9 MULMOD 8 8.636223825
## 10 EXP 10 13.862396840
## 11 SIGNEXTEND 5 3.818951990
## 12 LT 3 2.810866039
## 13 GT 3 2.738481791
## 14 SLT 3 2.111186002
## 15 SGT 3 2.100789703
## 16 EQ 3 2.260711593
## 17 ISZERO 3 1.558863407
## 18 AND 3 2.398774593
## 19 OR 3 2.413748126
## 20 XOR 3 2.425580175
## 21 NOT 3 1.789685034
## 22 BYTE 3 2.993651884
## 23 SHL 3 3.111447933
## 24 SHR 3 3.183037520
## 25 SAR 3 3.784480612
## 26 ADDRESS 2 3.163222518
## 27 ORIGIN 2 2.736283864
## 28 CALLER 2 2.422784513
## 29 CALLVALUE 2 1.564323423
## 30 CALLDATALOAD 3 2.549914234
## 31 CALLDATASIZE 2 1.247461040
## 32 CALLDATACOPY 2 6.752516773
## 33 CODESIZE 2 1.253545072
## 34 CODECOPY 2 6.429752378
## 35 GASPRICE 2 1.880551661
## 36 RETURNDATASIZE 2 1.317508330
## 37 RETURNDATACOPY 3 6.414569329
## 38 COINBASE 2 3.065764262
## 39 TIMESTAMP 2 1.582649091
## 40 NUMBER 2 1.594557610
## 41 DIFFICULTY 2 2.834234962
## 42 GASLIMIT 2 1.600701357
## 43 CHAINID 2 2.063376250
## 44 SELFBALANCE 5 8.011112947
## 45 POP 2 1.063372327
## 46 MLOAD 3 3.934224794
## 47 MSTORE 3 7.720280478
## 48 MSTORE8 3 3.116015842
## 49 JUMP 8 2.025454075
## 50 JUMPI 10 2.943757024
## 51 PC 2 1.141050631
## 52 MSIZE 2 1.229337034
## 53 GAS 2 1.200201012
## 54 JUMPDEST 1 0.895940166
## 55 PUSH1 3 2.046197721
## 56 PUSH2 3 2.520936198
## 57 PUSH3 3 2.646336651
## 58 PUSH4 3 2.741069355
## 59 PUSH5 3 2.864168713
## 60 PUSH6 3 2.897387897
## 61 PUSH7 3 3.087421868
## 62 PUSH8 3 3.115022526
## 63 PUSH9 3 3.221046699
## 64 PUSH10 3 3.304352788
## 65 PUSH11 3 3.446493329
## 66 PUSH12 3 3.534666331
## 67 PUSH13 3 3.596911006
## 68 PUSH14 3 3.740757271
## 69 PUSH15 3 3.875038393
## 70 PUSH16 3 3.882835511
## 71 PUSH17 3 4.040327112
## 72 PUSH18 3 4.180454019
## 73 PUSH19 3 4.282326525
## 74 PUSH20 3 4.333664248
## 75 PUSH21 3 4.404627278
## 76 PUSH22 3 4.527868757
## 77 PUSH23 3 4.654541123
## 78 PUSH24 3 4.690787524
## 79 PUSH25 3 4.760493210
## 80 PUSH26 3 4.969519426
## 81 PUSH27 3 5.003671677
## 82 PUSH28 3 5.088793090
## 83 PUSH29 3 5.171355803
## 84 PUSH30 3 5.236281159
## 85 PUSH31 3 5.421681386
## 86 PUSH32 3 5.420340579
## 87 DUP1 3 1.291904416
## 88 DUP2 3 1.272725020
## 89 DUP3 3 1.237409640
## 90 DUP4 3 1.222024420
## 91 DUP5 3 1.216052019
## 92 DUP6 3 1.270039064
## 93 DUP7 3 1.151166686
## 94 DUP8 3 1.138756406
## 95 DUP9 3 1.262427376
## 96 DUP10 3 1.206832378
## 97 DUP11 3 1.140096150
## 98 DUP12 3 1.272298937
## 99 DUP13 3 1.164645203
## 100 DUP14 3 1.166565630
## 101 DUP15 3 1.294571761
## 102 DUP16 3 1.160368011
## 103 SWAP1 3 1.450052352
## 104 SWAP2 3 1.472401432
## 105 SWAP3 3 1.467930468
## 106 SWAP4 3 1.457625533
## 107 SWAP5 3 1.439019812
## 108 SWAP6 3 1.506377711
## 109 SWAP7 3 1.609970272
## 110 SWAP8 3 1.452014333
## 111 SWAP9 3 1.435904730
## 112 SWAP10 3 1.691645473
## 113 SWAP11 3 1.422987649
## 114 SWAP12 3 1.517461974
## 115 SWAP13 3 1.520826603
## 116 SWAP14 3 1.404448493
## 117 SWAP15 3 1.698951404
## 118 SWAP16 3 1.634919153
## 119 EXP_arg1_cost 50 21.841726928
## 120 CALLDATACOPY_arg2_cost 3 0.019342866
## 121 RETURNDATACOPY_arg2_cost 3 0.002853493
## 122 CODECOPY_arg2_cost 3 0.005859348
## 123 DIV_expensive_cost 5 8.062037443
## 124 SDIV_expensive_cost 5 10.322538385
## 125 MOD_expensive_cost 5 8.685139137
## 126 SMOD_expensive_cost 5 9.273985940
## 127 ADDMOD_expensive_cost 8 13.519470818
## 128 MULMOD_expensive_cost 8 16.437403819
## alternative_gas_rel_diff alternative_gas_rel_stderr
## 1 0.377084637 0.10872309
## 2 0.242262988 0.19826137
## 3 0.214441394 0.25173204
## 4 0.324350326 0.23021271
## 5 0.001863017 0.29032846
## 6 0.209992133 0.20382487
## 7 0.078962615 0.22251890
## 8 0.303132115 0.24753967
## 9 0.079527978 0.19848501
## 10 0.386239684 0.14173338
## 11 0.236209602 0.21602778
## 12 0.063044654 0.32362864
## 13 0.087172736 0.33500825
## 14 0.296271333 0.14315311
## 15 0.299736766 0.14188966
## 16 0.246429469 0.26017722
## 17 0.480378864 0.19303463
## 18 0.200408469 0.27087467
## 19 0.195417291 0.26110631
## 20 0.191473275 0.26517602
## 21 0.403438322 0.18568146
## 22 0.002116039 0.23422470
## 23 0.037149311 0.15516530
## 24 0.061012507 0.21766280
## 25 0.261493537 0.23360376
## 26 0.581611259 0.23865972
## 27 0.368141932 0.29001080
## 28 0.211392256 0.22151990
## 29 0.217838289 0.19406091
## 30 0.150028589 0.16096928
## 31 0.376269480 0.09059396
## 32 2.376258387 0.17572609
## 33 0.373227464 0.08554432
## 34 2.214876189 0.16380942
## 35 0.059724170 0.29405211
## 36 0.341245835 0.10919314
## 37 1.138189776 0.24000759
## 38 0.532882131 0.28139651
## 39 0.208675455 0.14082478
## 40 0.202721195 0.13463487
## 41 0.417117481 0.32806270
## 42 0.199649321 0.12867971
## 43 0.031688125 0.27410133
## 44 0.602222589 0.43978474
## 45 0.468313837 0.17140321
## 46 0.311408265 0.14383390
## 47 1.573426826 0.28715198
## 48 0.038671947 0.18981304
## 49 0.746818241 0.30748473
## 50 0.705624298 0.30080047
## 51 0.429474685 0.10193130
## 52 0.385331483 0.09755122
## 53 0.399899494 0.08596790
## 54 0.104059834 0.08493671
## 55 0.317934093 0.34676295
## 56 0.159687934 0.30482262
## 57 0.117887783 0.29642493
## 58 0.086310215 0.30053289
## 59 0.045277096 0.31818113
## 60 0.034204034 0.33103908
## 61 0.029140623 0.33312799
## 62 0.038340842 0.35373569
## 63 0.073682233 0.35790090
## 64 0.101450929 0.36832761
## 65 0.148831110 0.36191673
## 66 0.178222110 0.37519721
## 67 0.198970335 0.37875812
## 68 0.246919090 0.38216921
## 69 0.291679464 0.37790038
## 70 0.294278504 0.38890239
## 71 0.346775704 0.39345143
## 72 0.393484673 0.39867831
## 73 0.427442175 0.39741153
## 74 0.444554749 0.41484526
## 75 0.468209093 0.42242837
## 76 0.509289586 0.42334878
## 77 0.551513708 0.42257956
## 78 0.563595841 0.43289003
## 79 0.586831070 0.43431661
## 80 0.656506475 0.43815554
## 81 0.667890559 0.44210959
## 82 0.696264363 0.44330323
## 83 0.723785268 0.45690675
## 84 0.745427053 0.46089702
## 85 0.807227129 0.45583571
## 86 0.806780193 0.47234773
## 87 0.569365195 0.17042570
## 88 0.575758327 0.19329260
## 89 0.587530120 0.18207800
## 90 0.592658527 0.18879780
## 91 0.594649327 0.19635672
## 92 0.576653645 0.19070946
## 93 0.616277771 0.14606003
## 94 0.620414531 0.14482635
## 95 0.579190875 0.18240080
## 96 0.597722541 0.17612130
## 97 0.619967950 0.15856245
## 98 0.575900354 0.16663904
## 99 0.611784932 0.15488576
## 100 0.611144790 0.14094916
## 101 0.568476080 0.17362179
## 102 0.613210663 0.14239805
## 103 0.516649216 0.15972352
## 104 0.509199523 0.14434311
## 105 0.510689844 0.14157567
## 106 0.514124822 0.14775849
## 107 0.520326729 0.16426507
## 108 0.497874096 0.16349395
## 109 0.463343243 0.17058121
## 110 0.515995222 0.14598489
## 111 0.521365090 0.16214342
## 112 0.436118176 0.19154389
## 113 0.525670784 0.15007233
## 114 0.494179342 0.15978026
## 115 0.493057799 0.16778033
## 116 0.531850502 0.15396497
## 117 0.433682865 0.21621020
## 118 0.455026949 0.19301292
## 119 0.563165461 0.20938970
## 120 0.993552378 0.80706950
## 121 0.999048836 0.48305230
## 122 0.998046884 0.47413362
## 123 0.612407489 0.18161379
## 124 1.064507677 0.20261588
## 125 0.737027827 0.16466207
## 126 0.854797188 0.17335483
## 127 0.689933852 0.26034875
## 128 1.054675477 0.18709200
maximum_gas_cost = max(gas_schedule_comparison[,!names(gas_schedule_comparison) %in% c('opcode')])
plot(gas_schedule_comparison$constant_current_gas, col='grey', xaxt='n', ylim=c(0,maximum_gas_cost * 1.1), xlab="", ylab="")
axis(1, at=1:nrow(gas_schedule_comparison), labels=gas_schedule_comparison$opcode, las=2)
points(gas_schedule_comparison$alternative_gas, col='orange', bg='orange', xaxt='n', pch=21)
legend(0, maximum_gas_cost, c("Alternative gas cost schedule", "Current gas cost schedule"), fill=c('orange', 'grey'), cex=2)
# just export the final compiled estimations to a file
write.csv(estimated_cost, "../../local/final_estimated_cost.csv", quote=FALSE, row.names=FALSE)
write.csv(gas_schedule_comparison, "../../local/gas_schedule_comparison.csv", quote=FALSE, row.names=FALSE)